package com.hdaccp.dao.impl;

import java.io.Serializable;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import com.hdaccp.dao.CommonDao;
import com.hdaccp.dao.UdetailsDao;
import com.hdaccp.entity.Udetails;
import com.hdaccp.util.BaseDao;

public class UdetailsDaoimpl extends BaseDao implements CommonDao,UdetailsDao {
    @Override
    public List getAll() {
    	return null;
    }

    @Override
    public Object getById(Serializable id) {
        return null;
    }

    @Override
    public boolean add(Object entity) {
        return false;
    }

    @Override
    public boolean update(Object entity) {
        return false;
    }

    @Override
    public boolean deleteById(Serializable id) {
        return false;
    }

	@Override
	public Udetails getBy(int id) {
		String sql = "select * from `udetails` where zid = ?";
    	Object[] params = {id};
    	Udetails list = new Udetails();
    	Udetails u = null;
    	ResultSet rs = super.executeQuery(sql, params);
    	try {
			while(rs.next()){
				u = new Udetails();
				u.setId(rs.getInt("id"));
				u.setName(rs.getString("name"));
				u.setPhone(rs.getString("phone"));
				u.setPfm(rs.getInt("pfm"));
				u.setCommunity(rs.getString("community"));
				u.setZid(rs.getInt("zid"));
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{
			try {
				super.closeAll(rs, rs.getStatement(), rs.getStatement().getConnection());
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
        return u;
	}

	@Override
	public boolean getupd(Udetails u) {
		String sql = "update `udetails` set `name`=?,`phone`=?,`community`=?,`pfm`=? where `zid`=?";
		Object[] params = {u.getName(),u.getPhone(),u.getCommunity(),u.getPfm(),u.getZid()};
		String sql1 = "update `zong` set `cname`=?,`uname` =? where id = ?";
		Object[] params1 = {u.getCommunity(),u.getName(),u.getZid()};
		super.executeUpdate(sql1, params1);
		return super.executeUpdate(sql, params);
	}
}
